import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 三石
 * Date: 2022-05-28
 * Time: 21:09
 */
public class Strtest {

        String str = new String("good");
        char[ ] ch = { 'a' , 'b' , 'c' };
        public static void main(String args[]){
            Strtest ex = new Strtest();
            ex.change(ex.str,ex.ch);
            System.out.print(ex.str + " and ");
            System.out.print(ex.ch);
        }
        public void change(String str,char ch[ ]){
            str = "test ok";
            ch[0] = 'g';
        }


        public static boolean isAdmin(String userId){
            return userId.toLowerCase()=="admin";
        }
        public static void main12(String[] args){
            System.out.println(isAdmin("Admin"));
        }

        private static void testMethod(){
            System.out.println("testMethod");
        }
        public static void main11(String[] args) {
            (( Strtest)null).testMethod();
        }

    public static void main10(String[] args) {

        char[] ch=new char[]{'a','b','c'};
        String s5=new String(ch);
        String s6="abc";
        System.out.println(ch);
        System.out.println(s5);
        System.out.println(s6==s5);
        System.out.println("========");

        String s1="hello";
        String s2="hello";
        String s3="HELLO";
        String s4=new String("bit");
        System.out.println(s1==s4);
        System.out.println(s1==s3);
        System.out.println(s1==s2);
    }

    /**
     * 字符串的截取
     * @param args
     */
    public static void main9(String[] args) {
        String s1="abcdefab";
        String ret=s1.substring(1);//从1下标往后截取
        String ret1=s1.substring(1, 4);//从11到4下标截取（注意，左闭右开）
        System.out.println(ret);
        System.out.println(ret1);
    }

    /**
     * 字符串拆分
     * @param args
     */
    public static void main8(String[] args) {
        String s="hello welcome to bit";
        String[] ret=s.split(" ");//遇到空格就成一组
                for(String s1 : ret){
                    System.out.println(s1);
                }

        System.out.println("===========");
        String s2="hello/welcome/to/bit";
                String[] ret1=s2.split("/",2);//最多分成2组
                for (String s3: ret1){
                    System.out.println(s3);
                }

        System.out.println("============");
        String s4="hello.welcome.to.bit";
        String[] ret2=s4.split("\\.");//点号需要\\.转义
        for (String s5: ret2){
            System.out.println(s5);
        }

    }

    public static void main7(String[] args) {
        String s="ababcdab";
        String ret=s.replace("ab","qq");
        System.out.println(ret);
        //全部替换

        String ret1=s.replaceFirst("ab","qq");
        System.out.println(ret1);
        //第一个替换
    }

    /**
     * 字符串大小写的转换
     * 原来的值不会变（产生了新对象）
     * @param args
     */
    public static void main6(String[] args) {
        String s="hello";
        String ret=s.toUpperCase();
        System.out.println(ret);

        System.out.println("=========");
        String s1="HELLO";
        String ret1=s1.toLowerCase();
        System.out.println(ret1);
    }

    /**
     * 把其他数据类型类型变成字符串
     * @param args
     */
    public static void main5(String[] args) {
        String s1=String.valueOf(123);
        String s2=String.valueOf(12.3);
        String s3=String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
    }
    /**
     * 从后往前找字符串
     * @param args
     */
    public static void main4(String[] args) {
        String s="abcdab";
        int index=s.lastIndexOf('a');
        System.out.println(index);

        String s2="hhh.mjih";
        int index2=s2.lastIndexOf(".");
        System.out.println(index2);
    }

    /**
     * 从前往后找字符串
     * @param args
     */
    public static void main3(String[] args) {
        String s1="hello";
        int index=s1.indexOf('l');
        //查找第一次出现的字符（从第0个开始）
        int index1=s1.indexOf('l',3);
        //从第3个下标开始
        int index2=s1.indexOf("el");
        //返回第一个数下标
        System.out.println(index2);
        System.out.println(index);
        System.out.println(index1);
    }

    /**
     * 将字符串逐个打印
     * @param args
     */
    public static void main2(String[] args) {
        String s1="abcdef";
        for (int i = 0; i <s1.length(); i++) {
            char ch=s1.charAt(i);
            System.out.print(ch+" ");
        }
    }

    /**
     * 比较字符串
     * @param args
     */
    public static void main1(String[] args) {
        String s1="hello";
        String s2="HELLO";
        String s3="hello";
        System.out.println(s1.compareTo(s3));
        System.out.println(s1.compareToIgnoreCase(s2));

        System.out.println(s1.compareTo(s2));
    }


}
